package com.fusion.core.crypto;

import com.fusion.core.CoreSubsystem;
import com.fusion.core.comm.networklayers.tcpnio.TCPNIONetworkLayer;
import com.fusion.core.crypto.cryptolayers.SSLCryptoLayer;
import com.fusion.core.crypto.cryptolayers.TranslationCryptoLayer;

import java.io.IOException;

/**
 * @author SwethaShivakumar 
 * Project: fusion
 * Date: Mar 11, 2009
 * URL: http://fusionwiki.co.cc
 * Mail Me At: shiva@fusionproject.co.cc
 */
public class CryptoManager  {
    private CryptoLayer cryptoLayer;
    private CoreSubsystem core;

    public CryptoManager(CoreSubsystem core) throws Exception {
        switch(core.getSettings().getInternal().getEncryption()) {
            case 1:
                if(T.t)T.info("Launching SSL cryptolayer");
                this.cryptoLayer = new SSLCryptoLayer(core);
                break;
            default:
                if(T.t)T.info("Launching translation cryptolayer");
                this.cryptoLayer = new TranslationCryptoLayer(core);
                break;
        }
        
        this.core = core;
    }

    public CryptoLayer getCryptoLayer() {
        return cryptoLayer;
    }

    public void init() throws IOException, Exception {
        TCPNIONetworkLayer networkLayer = core.getNetworkManager().getNetworkLayer();
        cryptoLayer.setNetworkLayer(networkLayer);
        cryptoLayer.init();
    }
}
